package com.dz.goods.service;

import com.dz.common.constants.CodeDomain;
import com.dz.goods.domain.entity.Sku;
import com.dz.goods.domain.repository.SkuRepository;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

/**
 * @ClassName : SkuServiceImpl
 * @Description :
 * @Author : ming
 * @Date: 2020-12-03 14:01
 **/
@Service
public class SkuServiceImpl implements SkuService{
    @Autowired
    private SkuRepository skuRepository;
    @Override
    public Sku findById(Long id) {
        return skuRepository.findById(id).get();
    }
    @Transactional
    @Override
    public Sku add(Sku sku) {
        return skuRepository.saveAndFlush(sku);
    }
    @Transactional
    @Override
    public void delete(Long id) {
        Sku sku = skuRepository.findById(id).get();
        sku.setDeleteFlag(Integer.valueOf(CodeDomain.DELETE_FLAG_YES.value()));
        skuRepository.saveAndFlush(sku);
    }
    @Transactional
    @Override
    public Sku edit(Sku sku) {
        return skuRepository.saveAndFlush(sku);
    }
}
